//
//  HJBubbleMessageCell.m
//  XWC
//
//  Created by Hello on 2022/10/25.
//

#import "HJChatMessageBubbleCell.h"
#import "HJChatMessageBubbleLayout.h"
#import "HJChatMessageModel.h"

@implementation HJChatMessageBubbleCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UIImageView *bubbleView = [UIImageView addToView:self.containerView];
        _bubbleView = bubbleView;
        bubbleView.userInteractionEnabled = YES;
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _bubbleView.frame = CGRectMake(0, 0, self.messageLayout.containerViewRect.size.width, self.messageLayout.containerViewRect.size.height);
}

- (void)setMessageLayout:(HJChatMessageLayout *)messageLayout {
    [super setMessageLayout:messageLayout];
    
    HJChatMessageBubbleLayout *messageCellData = (HJChatMessageBubbleLayout *)messageLayout;
    if (![messageCellData isKindOfClass:HJChatMessageBubbleLayout.class]) return;
    self.bubbleView.layer.mask = messageCellData.maskLayer;
    
    if (messageLayout.messageModel.messageType == HJMessageTypeNotice) {
        _bubbleView.backgroundColor = UIColor.whiteColor;
    } else if (messageLayout.messageModel.messageType == HJMessageTypeTransfer) {
        _bubbleView.backgroundColor = UIColor.tj_8667FEColor;
    } else {
        if (TJIM_isSelf(messageLayout.messageModel.senderId)) {
            _bubbleView.backgroundColor = UIColor.tj_EDE6FFColor;
        } else {
            _bubbleView.backgroundColor = UIColor.whiteColor;
        }
    }

}

@end
